<template>
    <el-form :model="form" style="width: 600px">
        <el-form-item label="角色名称:">
            <el-input v-model="form.roleName" />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit">修改</el-button>
        </el-form-item>
    </el-form>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios'
import { useRoute, useRouter } from 'vue-router';
import { ElMessage, ElMessageBox } from 'element-plus';
const route = useRoute();
const router = useRouter();
const form = reactive({
    roleId: route.query.roleId,
    roleName: '',
    updateName: localStorage.getItem("userName"),
    updateTime: new Date(),
    createName: '',
    createTime: '',
    isDeleted: false
})

//返填
const getRoleModel = () => {
    axios.get("/api/Role/GetRoleModel?roleId=" + form.roleId)
        .then(res => {
            form.roleName = res.data.data.roleName
            form.createName = res.data.data.createName
            form.createTime = res.data.data.createTime
        })
        .catch(err => {
            console.log(err);
        })
}
//修改
const onSubmit = () => {
    axios.post("/api/Role/Update", form)
        .then(res => {
            if (res.data.code == 0) {
                ElMessage.success("修改成功");
                router.push({
                    name: 'RoleList'
                })
            }
        })
        .catch(err => {
            console.log(err);
        })
}

onMounted(() => {
    getRoleModel();
})
</script>